<!DOCTYPE html>
<!-- The HTML 4.01 Transitional DOCTYPE declaration-->
<!-- above set at the top of the file will set     -->
<!-- the browser's rendering engine into           -->
<!-- "Quirks Mode". Replacing this declaration     -->
<!-- with a "Standards Mode" doctype is supported, -->
<!-- but may lead to some differences in layout.   -->


<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <script src="https://leanobservatory.googlecode.com/svn/trunk/js/common.js"></script>
    <title>GetUser</title>
  
  	<script>
  	var entorno;
  	var llave;
	var url = window.location.host;
	var urlTable = "https://docs.google.com/a/bbva.com/spreadsheet/ccc?key=0ApZ6EoQT3skrdERXMWRQazBvSE1YMXVCckVDbHUyaHc";
	
	if (url=="localhost:8888"){
		entorno="localhost:8888"
		llave = "703896943360-8cunhqat5ot0bhn8f2rl4g8ramktn7hb.apps.googleusercontent.com"	
	}else if (url=="pre.bbva-implantacioneseyp.appspot.com"){
		entorno="pre.bbva-implantacioneseyp.appspot.com"
	}else{
		entorno="bbva-implantacioneseyp.appspot.com"
		llave = "703896943360-i0d7bvjsmtoi09d90oasrb67plp0i2ko.apps.googleusercontent.com"
	}
	
	function createb(){
		// 'Getting' data-attributes using getAttribute
		var zombi = document.getElementById('signp');
		//var fruitCount = plant.getAttribute('data-clientid'); // fruitCount = '12'

		// 'Setting' data-attributes using setAttribute
		zombi.setAttribute('data-clientid',llave); // Pesky birds

	  
       var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
       po.src = 'https://apis.google.com/js/client:plusone.js';
       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    
	}
	
	
  	
  	
  	function signinCallback(authResult) {
  	  if (authResult['access_token']) {
  	    // Successfully authorized
  	    // Hide the sign-in button now that the user is authorized, for example:
  	    document.getElementById('signinButton').setAttribute('style', 'display: none');
  	    var martincito;
  	    
  	  gapi.client.load('oauth2', 'v2', function() {
  		  gapi.client.oauth2.userinfo.get().execute(function(resp) {
  		    // Shows user email
  		    martincito = resp.email;
  		    console.log(resp.email);
  	  		
  		    

  		  })
  		});
  	  
  	
 	

		 
  	  } else if (authResult['error']) {
  	    // There was an error.
  	    // Possible error codes:
  	    //   "access_denied" - User denied access to your app
  	    //   "immediate_failed" - Could not automatically log in the user
  	    // console.log('There was an error: ' + authResult['error']);
  	  }
	  loadVisualizationAPI();
  	}
	
	function loadVisualizationAPI() 
			{
				google.load("visualization", "1", {"packages": ["table"]});
				google.setOnLoadCallback(sendQuery);
				
			}
	function sendQuery() 
			{   
				gadgetHelper = new google.visualization.GadgetHelper();
				var opts = {dataType:'jsonp'};
				var query = new google.visualization.Query(urlTable, opts);	
			    var querytosend = "select * where A <> 'Url' and A <> ''";	
				query.setQuery(querytosend);	
				query.send(handleQueryResponse);
					
			}
	function handleQueryResponse(response) 
     {
				data = response.getDataTable();
				var filas = data.getNumberOfRows();
				console.log("filas "+filas);
				var fecha = new Date();
				fecha = fecha.getDate()+"/"+fecha.getMonth()+"/"+fecha.getFullYear();
				var url = gadgets.util.getUrlParameters()["parent"];
				data.setValue(filas,0,url);
				data.setValue(filas,1,fecha);
				data.setValue(filas,2,martincito);


	 }	
  	</script>
    
        
    
    <script src="https://leanobservatory.googlecode.com/svn/trunk/js/jquery.js" language="JavaScript"></script> 
	

	</head>
	<body onload="createb();">
		<p id="text"></p>
		<span id="signinButton">
		  <span
		  	id="signp"
		    class="g-signin"
		    data-clientid="xxx"
		    data-callback="signinCallback"
		    data-cookiepolicy="single_host_origin"
		    data-requestvisibleactions="http://schemas.google.com/AddActivity"
		    data-scope="https://www.googleapis.com/auth/userinfo.email">
		  </span>
		</span>

		
    <script type="text/javascript">
		 
    </script>
		
		
	</body>